package com.example.easyscript.controller.task;

import com.example.easyscript.common.minio.MinioUtil;
import com.example.easyscript.entity.task.Exception;
import com.example.easyscript.service.ExceptionService;
import com.example.easyscript.service.task.StatusImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author huzixian
 * @date 2023-03-08
 */
@Api(value = "StatusImageController", tags = "")
@Slf4j
@RestController
@RequestMapping(value = "/web/exception")
public class ExceptionController {

    @Resource
    private ExceptionService exceptionService;

    @Resource
    private MinioUtil minioUtil;

    @ApiOperation("获取异常列表")
    @GetMapping("/list")
    public List<Exception> list() {
        final List<Exception> list = exceptionService.list();
        list.stream().forEach(item -> {
            if(!item.getImageUrl().equals("")){
                item.setImageUrl(minioUtil.fileUrl(item.getImageUrl()));
            }
        });
        return list;
    }

    @ApiOperation("删除")
    @PostMapping("/delete/{id}")
    public void delete(@PathVariable String id) {
        exceptionService.removeById(id);
    }

}